<?php namespace Admin\Controller;
class IndexController extends CommonController{
    /**
     * 首页
     */
    public function index(){
        if (IS_POST){
            //获取post提交的班级名称
            $cname = $_POST['cname'];
            //调用model里面的没有结果集的exec方法
            M()->exec("insert into class set cname='$cname'");
            //调用controller里面的成功提示的方法
            $this->success("班级添加成功","Index.php?m=Admin"); exit;
        }
        //分配标签卡title 数据
        $this->assign("title","班级管理首页");
        //获取数据库class表数据按cid降序排列
        $data = M()->query("select * from class order by cid desc");
        //数据分配
        $this->assign("data",$data);
        //显示模板
        $this->display();
//        include './View/Index.php';
    }
    /**
     * 编辑
     */
    public function edit(){
        if (IS_POST){
            //获取post 提交的参数
            $cid = $_POST['cid'];
            $cname = $_POST['cname'];
            //执行数据库表class的修改
            M()->exec("update class set cname='{$cname}' where cid={$cid}");
            //成功提示
            $this->success("班级修改成功哦","Index.php?m=Admin");exit;
        }
        $this->error("请求失败哦！","Index.php?m=Admin");
    }
    /**
     * 删除班级
     */
    public function del(){
        if (IS_POST){
            $cid = $_POST['cid'];
            M()->exec("delete from class where cid={$cid}");
            $this->success("班级删除成功啦！","Index.php?m=Admin");exit;
        }
        $this->error("请求失败哦！","Index.php?m=Admin");
    }
    public function out(){
        if (IS_POST){
            $cid = $_POST['cid'];
            $this->success("退出成功啦！","Index.php?m=Admin");exit;
        }
        $this->error("请求失败哦！","Index.php?m=Admin");
    }

    
}